'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  /* test login */
  async index() {
    const { ctx } = this;
    // test the page render:
    // await ctx.render("index");

    if (ctx.session.user) {
      await ctx.render("index");
    } else {
      ctx.redirect("/login");
    }
  }
  async login() {
    await this.ctx.render("login");
  }
  async logout() {
    this.ctx.session.user = '';
    this.ctx.redirect("/login");
  }
  async doLogin() {
    // this.logger.debug(`test logger module to dbug😎`);
    // console.log(this);
    // console.log(this.ctx);
    console.log(` 😂check ctx.request object`);
    console.log(this.ctx.request);
    console.log(`😂😂test by naive`);
    let username = this.ctx.reqeust.body.username;
    let password = this.ctx.request.body.password;
    if (username == "x" && password == "x ") {
      // this.ctx.session.user = username;
      // this.ctx.redirect("/")

    } else {
      this.ctx.redirect("/login");
    }
  }
  /* 单元测试的时候将其打开(或者修改测试中的文件名) */
  async index_old() {
    const { ctx } = this;
    // ctx.body = 'hi, egg';
    // you can create web page there by write content to the ctx.body to renader the conteent to show.
    ctx.body = 'hi,egg';
    // ctx.body = "<h1>Hello🦊 </h1>";

    // await ctx.render("index",{fruits:["🍌 ","🍎 ","🍐 "]});
  }

  async jspang() {
    const { ctx } = this;
    ctx.body = 'hi,egg';
    // ctx.body = "<h1 > hello jspang</h1>"


  }

}

module.exports = HomeController;
